namespace cvm
{
	template<typename T>
	struct ValueType
	{
		T m;
		static void Create(VM& vm) { }
		static void Destroy(VM& vm) { }
		static void Equals(VM&  vm) { A0_ANY(vm); A1_ANY(vm); vm.Push(a0 == a1); }
	};

	struct Int : ValueType<int>
	{
		TYPE_IMPL("Int");
		static void Add(VM& vm) { A0(Int, vm); A1(Int, vm); a0.m += a1.m; DecSp(); }
	};
	Table Int::table = { 
		Int::Create, 
		Int::Destroy, 
		Int::GetTable, 
		Int::TypeName, 
		Int::Equals, 
		Int::Add 
	};

	struct Function : ValueType<int>
	{
		TYPE_IMPL("Function");
	};
	Table Function::table = { 
		Function::Create, 
		Function::Destroy, 
		Function::GetTable, 
		Function::TypeName, 
		Function::Equals, 
	};

	struct Object
	{
	};

	struct Num
	{
		Table table;
		void* value;

		void Add(VM& vm) { table[0](vm); }
		void Eq(VM& vm) { table[1](vm); }
	};

	struct Type
	{
		Table table;
		
		void GetTable(VM& vm) { table[0](vm); }
		void TypeName(VM& vm) { table[1](vm); }
	};

	Table FltTable = { Flt::Add, Flt::Eq };
	
	void IntToValue(Value& v, int n=0) {
		v.table = IntTable;
		v.holder.As<int>() = n;
	}

	void FltToValue(Value& v, float f=0.0f) {
		v.table = FltTable;
		v.holder.As<float>() = n;
	}
}